/*! ******************************************************************************
 *
 * Created on 2022年2月25日
 *
 * Copyright(c) YuZhou Big Data Laboratory CO.,Ltd, 2022.  All rights reserved.
 *
 *******************************************************************************
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with
 * the License. You may obtain a copy of the License at
 *
 *    http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 *
 ******************************************************************************/

package org.yzbdl.lanius.core.net;

import cn.hutool.core.util.ArrayUtil;

/**
 * 
 * 客户端只需要处理以下状态码的请求，其余状态为无法处理的错误状态。
 * 
 * @author hs@yzbdl.ac.cn
 *
 */
public class HttpStatus {

    /** 正常访问 {@code 200 OK} (HTTP/1.0 - RFC 1945) */
    public static final int SC_OK = 200;

    /** 分段内容 {@code 206 Partial Content} (HTTP/1.1 - RFC 2616) */
    public static final int SC_PARTIAL_CONTENT = 206;

    /** 未登录认证 {@code 401 Unauthorized} (HTTP/1.0 - RFC 1945) */
    public static final int SC_UNAUTHORIZED = 401;

    /** 未付费 {@code 402 Payment Required} (HTTP/1.1 - RFC 2616) */
    public static final int SC_PAYMENT_REQUIRED = 402;

    /** 权限不足 {@code 403 Forbidden} (HTTP/1.0 - RFC 1945) */
    public static final int SC_FORBIDDEN = 403;

    /** 服务端错误 {@code 500 Server Error} (HTTP/1.0 - RFC 1945) */
    public static final int SC_INTERNAL_SERVER_ERROR = 500;

    /** 服务端错误 {@code 501 Server Error} (HTTP/1.0 - RFC 1945) */

    public static final int PLUGIN_NOT_FIND = 501;
    private static int[] okCodesArray = new int[] {SC_OK, SC_PARTIAL_CONTENT};

    /**
     * 根据http response code判断请求是否可继续正常访问
     * <p>
     * 目前只有 200, 206为正常code
     * 
     * @param responseCode
     * @return
     */
    public static boolean isAccessOk(int responseCode) {
        return ArrayUtil.contains(okCodesArray, responseCode);
    }

}
